import java.util.Collections;
import java.util.LinkedList;

class MinStack<T extends Comparable> {

	private LinkedList<T> list = new LinkedList<T>();

	public T pop() {
		return list.removeLast();
	}

	public void push(T t) {

		list.add(t);
		Collections.sort(list);

	}

	public T min() {
		return list.getLast();
	}
}

class Stack<T extends Comparable> extends MinStack<T> {

	private LinkedList<T> list = new LinkedList<T>();

	public T pop() {
		super.pop();
		return list.removeLast();
	}

	public void push(T t) {
		super.push(t);
		list.add(t);
	}

}

public class Test {

	/**
	 * @param args
	 */
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int k = 2;

		int[] array = new int[] { 56, 34, 205, 12, 78, 44, 21, 15, 30, 100, 60,
				77, 1, 19 };

		findKthLargestValue(array, k, 0, array.length - 1);

		System.out.println(array.length);

		for (int i = array.length - k; i < array.length; i++) {
			System.out.print(i + " " + array[i] + " \n");
		}

	}

	private static void findKthLargestValue(int[] array, int k, int l, int r) {

		int pivot = array[(l + r) / 2];

		int left = l;
		int right = r;

		while (left <= right) {
			while (array[left] < pivot)
				left++;
			while (array[right] > pivot)
				right--;
			if (left <= right) {
				int tmp = array[left];
				array[left] = array[right];
				array[right] = tmp;
				left++;
				right--;
			}
		}
		if (r - left + 1 > k) {
			if (r - left> 0) {
				findKthLargestValue(array, k, left, r);
			}
		} else {
			if (right - l > 0) {
				findKthLargestValue(array, k - (r - left + 1), l, right);
			}
		}
	}

}
